# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import os
from cerbero.utils.shell import which

class Recipe(recipe.Recipe):
    name = 'glib-networking'
    version = '2.50.0'
    licenses = [License.LGPLv2Plus]
    stype = SourceType.TARBALL
    url = 'http://ftp.gnome.org/pub/gnome/sources/glib-networking/2.50/glib-networking-%(version)s.tar.xz'
    autoreconf = True
    configure_options = "--without-ca-certificates --enable-more-warnings"
    deps = ['glib', 'gnutls']
    patches = ['glib-networking/0001-Add-support-for-static-modules.patch',
               'glib-networking/0002-Get-the-CA-certificate-path-from-the-environment-var.patch',
               'glib-networking/0003-gnutls-Use-db-relative-to-libglib-2.0-if-needed.patch',
               'glib-networking/0004-gtlsbackend-gnutls-Get-anchor-file-relative-to-libgi.patch']

    files_misc = ['lib/gio/modules/libgiognutls%(mext)s']
    files_lang = ['glib-networking']

    def prepare(self):
        querymodule_path = os.path.join(self.config.prefix, 'bin', 'gio-querymodules')
        if self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
          # For the universal build we need to use the right gio-querymodules
          arch = self.config.target_arch
          arch_path = os.path.join(self.config.prefix, arch, 'bin', 'gio-querymodules')
          # Only for the universal builds
          if os.path.exists(arch_path):
              querymodule_path = arch_path

        if self.config.cross_compiling():
          querymodule_path = which('true')

        if self.config.target_platform in [Platform.ANDROID]:
          self.append_env['CFLAGS'] = ' -DGST_CA_CERTIFICATES_FROM_ENV'

        self.config_sh = 'GIO_QUERYMODULES=%s %s' % (querymodule_path, self.config_sh)
